Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Services.Exceptions
Namespace SGW.ComunicadorWeb

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' The ViewDynamicModule class displays the content
    ''' </summary>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public MustInherit Class ViewSgw_Categorias
        Inherits Entities.Modules.PortalModuleBase
        Implements Entities.Modules.IActionable
        Dim PageIndex As Integer

#Region "Event Handlers"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Page_Load runs when the control is loaded
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            Try
                Dim objPortalSecurity As New PortalSecurity

                If Request.IsAuthenticated = False Then
                    If PortalSettings.LoginTabId <> -1 Then
                        'user defined tab
                        Response.Redirect(NavigateURL(PortalSettings.LoginTabId), True)
                    Else
                        'Admin Tab
                        Response.Redirect(NavigateURL("Login"), True)
                    End If
                End If

                ' If this is the first visit to the page, populate the site data
                If Page.IsPostBack = False Then

                    If Not Request.QueryString("CurrentPage") Is Nothing Then
                        PageIndex = CType(Request.QueryString("CurrentPage"), Integer)
                    Else
                        PageIndex = 1
                    End If

                    If Not Request.QueryString("PageRecords") Is Nothing Then
                        'ddlRecordsPerPage.SelectedValue = Request.QueryString("PageRecords")
                    End If

                    BindData()

                End If

            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub


        Protected Function GetCategoriaEditUrl(ByVal CategoriaID As String) As String

            Return NavigateURL(Me.TabId, "", "sgwcomunicador=EditCategoria", "CategoriaID=" & CategoriaID)

        End Function

        Protected Sub cmdAddCategoria_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddCategoria.Click
            Try
                Response.Redirect(NavigateURL(Me.TabId, "", "sgwcomunicador=EditCategoria"), True)
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try

        End Sub

        Private Sub BindData()

            Dim TotalRecords As Integer

            Dim PageSize As Integer = 10
            Dim CurrentPage As Integer = PageIndex

            'Me.LabelBienvenido.Text = Replace(Localization.GetString("LabelBienvenido.Text", Me.LocalResourceFile), "[USERNAME]", Me.UserInfo.DisplayName)

            Dim objCategorias As New SGW_CategoriasController
            Dim colCategorias As List(Of SGW_CategoriasInfo)

            colCategorias = objCategorias.GetAllSGW_Categoriass(PortalId)

            If colCategorias.Count > 0 Then
                lstCategorias.DataSource = colCategorias
                lstCategorias.DataBind()
                'InitializePaging(PAGINGCONTROLAbiertos, TotalRecordsActivos, PageSize)
            Else
                lstCategorias.Visible = False
                'LabelNoActivos.Visible = True
                'LabelNoCategorias.Text = "No Hay Temas Activos..."
                'Me.PAGINGCONTROLAbiertos.Visible = False
            End If

        End Sub
        Private Sub InitializePaging(ByVal ctlPagingControl As DotNetNuke.UI.WebControls.PagingControl, ByVal TotalRecords As Integer, ByVal PageSize As Integer)

            ctlPagingControl.TotalRecords = TotalRecords
            ctlPagingControl.PageSize = PageSize
            ctlPagingControl.CurrentPage = PageIndex

            Dim strQuerystring As String = ""
            'If ddlRecordsPerPage.SelectedIndex <> 0 Then
            '    strQuerystring += "&PageRecords=" + ddlRecordsPerPage.SelectedValue
            'End If
            'If intPortalID >= 0 Then
            '    strQuerystring += "&pid=" + intPortalID.ToString
            'End If
            'If strLogTypeKey <> "*" AndAlso strLogTypeKey <> "" Then
            '    strQuerystring += "&LogTypeKey=" + strLogTypeKey
            'End If
            ctlPagingControl.QuerystringParams = strQuerystring
            ctlPagingControl.TabID = TabId
        End Sub
#End Region

#Region "Optional Interfaces"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Registers the module actions required for interfacing with the portal framework
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
            Get
                Dim Actions As New Entities.Modules.Actions.ModuleActionCollection
                Actions.Add(GetNextActionID, Localization.GetString(Entities.Modules.Actions.ModuleActionType.AddContent, LocalResourceFile), Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl(), False, Security.SecurityAccessLevel.Edit, True, False)
                Return Actions
            End Get
        End Property

#End Region

        Protected Sub cmdCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
            Try
                Response.Redirect(NavigateURL(), True)
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub
    End Class

End Namespace
